package hammersmith.local.valueobjects;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class ShoppingCartTableRenderer extends DefaultTableCellRenderer {
	
	private ShoppingCart cart;
	
	public ShoppingCartTableRenderer(ShoppingCart cart){
		this.cart=cart;
	}
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {

		Component cell = super.getTableCellRendererComponent(table, value,
				isSelected, hasFocus, row, column);
		
		setHorizontalAlignment( JLabel.CENTER );

		try {

			if (row == cart.getList().size()+1) {
				Font font = cell.getFont();
		        cell.setFont(font.deriveFont(Font.BOLD));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return cell;
	}
}